<extend name="Public:base" />
<block name="content">
	<form method="post" id="validation-form" action="{:U('Category/delfault')}">
		<div class="table-responsive">
    	<table class="table table-striped table-bordered table-hover search-form" id="nav-table">
        <thead>
        <th>故障名称：<input name="name" type="text" placeholder="输入名称" value="{:I('name')}" />
        分类：<select name="catype">
                <option value="0">请选择类型</option>
                <volist name="category" id="v">
					<php>if(I('catype')== $v['category_id']){</php>
					<option value="{$v.category_id}" selected="selected">{$v.path_name}</option>
					<php>}else{</php>
                    <option value="{$v.category_id}">{$v.path_name}</option>
                	<php>}</php>
				</volist>
            </select>
        <a class="btn btn-primary radius5 btn-sm" href="javascript:;" id="search" url="{:U('Category/fault')}">查询</a>
				<a  style="{$update==1?'':'display: none'}" href="{:U('Category/addfault')}" class="btn btn-primary radius5 btn-sm">添加故障</a>
				<input  style="{$delete==1?'':'display: none'}" id="submitBtn" type="submit"  value="删除"  class="btn btn-danger radius5 btn-sm" ></th>
				</thead>
   		</table>
		</div>
<div class="table-responsive">
	<table class="table table-striped table-bordered table-hover" id="mytable">
		<thead>
			<tr>
				<th class="center" style="width: 30px"><input id="CheckAll" type="checkbox" /></th>
				<th>序号</th>
				<th>故障</th>
				<th>分类视图</th>
				<th>故障类型</th>
				<th>描述</th>
				<th>顺风价</th>
				<th>标准价</th>
				<th>专修价</th>
				<th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
			</tr>
		</thead>
		<tbody>
				<volist name="fault" id="m">
				<tr>
					<td class="center"><input name="fault[]" value="{$m.fault_id}" type="checkbox" /></td>
					<td>{$key+1}</td>
					<td>{$m.name}</td>
					<td>{$m.path_name}</td>
					<td>{$m.fault_type}</td>
                        <td>{$m.desc}</td>
					<td>{$m.wind}</td>
                        <td>{$m.standard}</td>
                        <td>{$m.expert}</td>
					<td>{$m.order}</td>
					<td>
						<?php
						switch($m['status']){
							case '1':
							echo '<span class="green bold">启用</span>';
							break;
							case '2':
							echo '<span class="red bold">禁用</span>';
							break;
						}
						?>
					</td>
                        <td>
                            <a href="{:U('category/editfault')}/id/{$m.fault_id}" class="btn btn-xs btn-info radius5">
                                <i class="ace-icon fa">编辑</i>
                            </a>
                        </td>
				</tr>

				</volist>

				<tr>
					<td colspan="20" class="page">{$page}</td>
				</tr>
		</tbody>
	</table>
</div>
</form>
</block>
<block name="javascript">
<script>
$(function(){

	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });

	$('#CheckAll').click(function () {
		$("input[name='fault[]']").prop('checked', this.checked);
	})

	$("#submitBtn").click(function(){
		var result = new Array(), str = '';
		$('input[name="fault[]"]:checked').each(function () {
			result.push($(this).val());
		});
		var str = result.join(',');
		if (str == '') {
			$.jbox.info('没有选中任何数据！','提示');
			return false;
		}
		var submit = function (v, h, f) {
			if (v == 'ok') {
				$('#validation-form').ajaxSubmit(function(data){
					if(data=='1'){
						$.jbox.tip("正在删除数据...", 'loading');
						// 模拟2秒后完成操作
						window.setTimeout(function () { $.jbox.tip('删除成功。', 'success');location.reload()}, 1000);
					}else if(data=='-1'){
						$.jbox.info("删除失败!",'提示');
					}
				});
			}
			else if (v == 'cancel') {
				// 取消
			}

			return true; //close
		};

		$.jbox.confirm("确定要删除数据吗？", "提示", submit);

		return false;
	});

});
</script>
</block>